package com.aef.utils;

import org.apache.log4j.Logger;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by cyb on 2016/9/13 0013.
 */
public class ImageUtils {
	private static final Logger log =  Logger.getLogger(ImageUtils.class);
	public static String getImageStr(InputStream in,String type) {
		byte[] data = null;
		try {
			data = new byte[in.available()];
			in.read(data);
			BASE64Encoder encoder = new BASE64Encoder();
			return "data:"+type+";base64,"+encoder.encode(data);
		} catch ( IOException e ) {
			log.error("读取文件流失败",e);
		} finally {
			try {
				in.close();
			} catch ( IOException e ) {
				log.error("关闭文件流失败",e);
			}
		}
		return null;
	}
}
